﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccessLayer.Models
{
    public interface IAppRepository
    {
        IQueryable<Application> FindAllApplication(int userid);
        Application FindApplication(int id);
    }

    public class ApplicationRepository : IAppRepository
    {
        private LOSEntities db = new LOSEntities();

        //Query Methods
        public IQueryable<Application> FindAllApplication(int userid)
        {
            var user = db.Users.Single(u => u.UserId == userid);
            return db.Applications.Where(d => d.CreatorId == user.RoleId);
        }

        //Query Methods
        public Application FindApplication(int id)
        {
            return db.Applications.SingleOrDefault(d => d.AppId == id);
        }
    }
}
